<template>
  <basic-container>
    <avue-crud
      :option="option"
      :search.sync="search"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @sort-change="sortChange"
      @on-load="onLoad"
    >
      <template slot-scope="{row}" slot="codeAdvanceRate">
        <div>{{row.codeAdvanceRate}}%</div>
      </template>
      <template slot-scope="{row}" slot="rateApt">
        <div>{{row.rateApt}}%</div>
      </template>
      <template slot-scope="{row}" slot="rateCr">
        <div>{{row.rateCr}}%</div>
      </template>
      <template slot-scope="{row}" slot="rateDe">
        <div>{{row.rateDe}}%</div>
      </template>
    </avue-crud>
   
  </basic-container>
</template>

<script>
import { getList } from "@/api/rb-oem/settlement/settlement";

import { mapGetters } from "vuex";
export default {
  data() {
    return {
      form: {},
      query: {},
      search: {},
      loading: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      option: {
        height: "calc(50vh - 50px)",
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        viewBtn: false,
        editBtn: false,
        addBtn: false,
        delBtn: false,
        selection: true,
        searchMenuSpan: 24,
        columnBtn: false,
        labelWidth: 120, //弹出表单的标题的统一宽度
        searchLabelWidth: 120, //搜索框标题宽度
        menuWidth: 100, //操作栏宽度
        emptyBtnText:'重置',
        menu:false,
        column: [
          {
            label: "服务商编号",
            prop: "serviceNo",
            type: "input",
            ////sortable: true,
            search: true,
            overHidden: true,
            minWidth:110,
          },
          {
            label: "服务商名称",
            prop: "serviceName",
            type: "input",
            search: true,
            overHidden: true,
            minWidth:170
          },
          {
            label: "客户经理编号",
            prop: "managerNo",
            type: "input",
            search: true,
            overHidden: true,
            minWidth:150
          },
          {
            label: "客户经理名称",
            prop: "managerName",
            type: "input",
            search: true,
            overHidden: true,
            minWidth:94
          },
          {
            label: "通道名称",
            prop: "aisleName",
            type: "input",
            search: true,
            overHidden: true,
            minWidth:70
          },
          {
            label: "业务类型",
            prop: "businessType",
            type: "input",
            // search: true,
            overHidden: true,
            minWidth:70
          },
          {
            label: "支付类型",
            prop: "payType",
            type: "input",
            // search: true,
            overHidden: true,
            minWidth:70
          },
          {
            label: "垫资费率",
            prop: "codeAdvanceRate",
            type: "input",
            // search: true,
            overHidden: true,
            minWidth:70
          },
          {
            label: "结算底价",
            prop: "rateApt",
            type: "input",
            // search: true,
            overHidden: true,
            minWidth:70
          },
          {
            label: "贷记卡费率",
            prop: "rateCr",
            type: "input",
            // search: true,
            overHidden: true,
            minWidth:90
          },
          {
            label: "借记卡费率",
            prop: "rateDe",
            type: "input",
            // search: true,
            overHidden: true,
            minWidth:90
          },
          {
            label: "借记卡封顶",
            prop: "rateMax",
            type: "input",
            // search: true,
            overHidden: true,
            minWidth:90
          },
          {
            label: "状态",
            prop: "status",
            type: "input",
            // search: true,
            overHidden: true,
            minWidth:70
          },
          {
            label: "生效日期",
            prop: "createTime",
            type: "input",
            // search: true,
            overHidden: true,
            sortable: true,
            minWidth:150
          }
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.trade_add, false),
        viewBtn: this.vaildData(this.permission.trade_view, false),
        delBtn: this.vaildData(this.permission.trade_delete, false),
        editBtn: this.vaildData(this.permission.trade_edit, false),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
    // 交易状态
    rptPayStateType() {
      return (row) => {
        if(row.rptPayState==0){
          return '#E6A23C' //未支付
        }else if(row.rptPayState==1&&row.rptIsRefund!==0){
          return '#6463bf' //支付成功（已退款）
        }else if(row.rptPayState==1){
          return '#67C23A' //支付成功
        }else if(row.rptPayState==2){
          return '#909399'    //支付失败
        }else if(row.rptPayState==3){
          return '#909399' //取消支付
        }else if(row.rptPayState==4){
          return '#909399' //退款中
        }else if(row.rptPayState==5){
          return '#2fdeebf2' //已退款
        }else if(row.rptPayState==6){
          return '#909399' //退款失败
        }else{
          return '#909399' 
        }
      };
    },
    exhibition() {
      return (val) => {
        if (val == "" || val == "-1") {
          return (val = 0);
        } else {
          return val;
        }
      };
    },
  },
  watch: {
    "search.timeData"(val){
      if(val){
        this.search.beginTime = val[0];
        this.search.endTime = val[1];
      }else{
        this.search.beginTime = "";
        this.search.endTime = "";
      }
    }
  },
  created(){
    // this.getServiceInfoSimpleList({isSelectChild:0})
  },
  methods: {
     // 获取 代理商
    // getServiceInfoSimpleList(param) {
    //   serviceInfoSimpleList(param).then((res) => {
    //     // this.rptNoList = res.data.data.records;
    //     const column = this.findObject(this.option.column, "serviceNo");
    //     column.dicData = res.data.data;
    //     console.log(res.data.data)
    //   })
    // },
    /**
     * @func edit,view 打开之前回调
     * */
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        // getDetail(this.form.id).then(res => {
        //   this.form = res.data.data;
        // });
      }
      done();
    },
    /**
     * @func 重置
     * @desc 重置查询条件
     * */
    searchReset() {
      this.query = {};
      this.search = {};
      this.$set(this.search, 'timeData', ["",""])
      this.onLoad(this.page);
    },
    /**
     * @func 搜索
     * @desc 根据条件查询
     * @param {params} params --- 条件查询
     * */
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    /**
     * @func 选中单元格
     * @desc 选中单元格数据
     * @param {list} list --- 选中单元格数据-数组
     * */
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    /**
     * @func 分页页码
     * @desc 分页页码改变时会触发
     * */
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      // this.refreshChange();
    },
    /**
     * @func 当前页个数
     * @desc pageSize改变时会触发
     * */
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      // this.refreshChange();
    },

    /**
     * @func 刷新
     * @desc 点击刷新按钮触发该事件
     * */
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    /**
     * @func 初始化
     * @desc 表格初始化查询数据
     * */
    onLoad(page, params = {}) {
      this.loading = true;
      if(this.query.isSelectChildArr){
        this.query.isSelectChild = this.query.isSelectChildArr[0];
      }
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    /**
     * @func 排序
     * @desc 根据表格字段排序
     * */
    sortChange(val) {
      if (val.order == "ascending") {
        //正序
        this.query.ascs = val.prop;
        this.query.descs = "";
      } else {
        //倒序
        this.query.descs = val.prop;
        this.query.ascs = "";
      }
      this.refreshChange();
    }
  },
};
</script>

<style lang="scss" scoped>

</style>
